"use strict";
cc._RF.push(module, 'd8293B5ciNMf61djWZgvP0z', 'addDestok');
// scripts/engines/components/addDestok.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var MainRoot_1 = require("../../Game/MainRoot");
var gameEngine_1 = require("../gameEngine");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
/**添加快捷方式 桌面 */
var addDestok = /** @class */ (function (_super) {
    __extends(addDestok, _super);
    function addDestok() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.ShortcutBtn = null;
        _this.arrowNode = null;
        _this.FirstKey = "get-First-Add";
        /**最后一次进入的日期 日 */
        _this.TimeDay = "get-End-timeDay";
        _this.tt = null;
        return _this;
        // update (dt) {}
    }
    addDestok.prototype.arrowAni = function () {
        var tween = cc.tween(this.arrowNode).by(1, { y: 20 }).by(1, { y: -20 });
        cc.tween(this.arrowNode).repeatForever(tween).start();
    };
    addDestok.prototype.hideArrow = function () {
        this.arrowNode.active = false;
    };
    addDestok.prototype.onLoad = function () {
        this.tt = window['tt'];
        this.ShortcutBtn.on(cc.Node.EventType.TOUCH_END, this.onBtnMe, this);
        var that = this;
        console.info("添加快捷方式 onBtnMe", this.tt);
        this.arrowAni();
        this.hideArrow();
        if (this.tt) {
            //字节跳动 字节跳动lite 和西瓜拒审 关闭
            if (!MainRoot_1.default.isShortcutOpen()) {
                this.node.active = false;
                this.hideArrow();
                return;
            }
            this.tt.onShow(function (res) {
                console.log("启动参数如下：", res);
                console.log("启动参数如下：", res.query);
                console.log("来源信息如下：", res.refererInfo);
            });
            this.check();
            this.tt.checkShortcut({
                success: function (res) {
                    console.info("success快捷方式", res);
                    if (res.status.exist) {
                        that.node.active = false;
                        console.info("success快捷方式存在");
                    }
                    else {
                        console.info("success快捷方式不存在");
                    }
                    //获取快捷方式是否存在 res.status.exist
                },
                fail: function (res) {
                    console.info("fail快捷方式检查onLoad", res.errMsg);
                }
            });
        }
        else {
            // this.node.active = false
        }
    };
    addDestok.prototype.onBtnMe = function () {
        console.info("添加快捷方式 onBtnMe");
        // O1HD.getModules().uiControlModule.showMessageBox("添加失败");
        var self = this;
        if (this.tt) {
            console.info("添加快捷方式");
            gameEngine_1.default.getServices().miniGameSrv.getAppApiInstance().reportAnalytics('addDestok', { addDestok: "主界面点击添加桌面" });
            this.tt.addShortcut({
                success: function (res) {
                    self.node.active = false;
                    self.hideArrow();
                    var key = gameEngine_1.default.getServices().localStorageSrv.getStorage(self.FirstKey);
                    if (key && Number(key) == 1) {
                        console.info("已经添加过快捷方式");
                    }
                    else {
                        console.info("添加快捷方式成功");
                        self.addRewarded();
                        gameEngine_1.default.getServices().localStorageSrv.setStorage(self.FirstKey, 1);
                        gameEngine_1.default.getServices().miniGameSrv.getAppApiInstance().reportAnalytics('addDestok', { addDestok: "主界面点击添加桌面成功" });
                    }
                },
                fail: function (res) {
                    console.info("添加快捷方式失败", res);
                    gameEngine_1.default.getServices().miniGameSrv.getAppApiInstance().reportAnalytics('addDestok', { addDestok: "主界面点击添加桌面失败" });
                    gameEngine_1.default.getModules().uiControlModule.showMessageBox("添加失败");
                }
            });
        }
        else {
            this.addRewarded();
            gameEngine_1.default.getServices().localStorageSrv.setStorage(self.FirstKey, 1);
        }
    };
    addDestok.prototype.start = function () {
        //弹窗出来的 添加 打点一次  
    };
    //从桌面进打点        
    addDestok.prototype.check = function () {
        //刷新时间 为0点
        var options = this.tt.getLaunchOptionsSync();
        console.info("checkoptions", options);
        if (options.scene == "021020") //抖音桌面图标
         {
            console.info("check");
            gameEngine_1.default.getServices().miniGameSrv.getAppApiInstance().reportAnalytics('addDestok', { addDestok: "抖音桌面进入" });
            var curTime = new Date().getDate();
            console.info("checkcurTime", curTime);
            var key = gameEngine_1.default.getServices().localStorageSrv.getStorage(this.TimeDay);
            if (key) { //
                if (Number(key) == curTime) { //当天重复进 不给奖励
                    console.info("checkcurTime 不给奖励", curTime);
                }
                else { //刷新  给奖励
                    console.info("checkcurTime 给奖励", curTime);
                    this.addRewarded();
                    gameEngine_1.default.getServices().localStorageSrv.setStorage(this.TimeDay, curTime);
                }
            }
            else { //第一次进  给奖励
                console.info("checkcurTime  第一次进给奖励", curTime);
                this.addRewarded();
                gameEngine_1.default.getServices().localStorageSrv.setStorage(this.TimeDay, curTime);
            }
        }
    };
    addDestok.prototype.addRewarded = function () {
        // services().userSrv.addPowerOfVideo();
        // O1HD.getServices().userSrv.setCoins(1,true);
        // modules().uiControlModule.showGetRewarded(REWARD_TYPE.COIN,1,"恭喜");
    };
    __decorate([
        property({ type: cc.Node, displayName: "快捷方式按钮" })
    ], addDestok.prototype, "ShortcutBtn", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "箭头节点" })
    ], addDestok.prototype, "arrowNode", void 0);
    addDestok = __decorate([
        ccclass
    ], addDestok);
    return addDestok;
}(cc.Component));
exports.default = addDestok;

cc._RF.pop();